package controlLayer;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.List;

import controlLayer.ScheduleCtr;
import controlLayer.ClassCtr;
import modelLayer.Block;
import modelLayer.ClassCon;
import modelLayer.ScheduleCon;
import modelLayer.TeachingBlock;
import modelLayer.Class;

public class Main {
	
	public Main() {
		runApplication();
	}
	
	public static void main(String[] args){
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					runApplication();
				}
				catch (Exception e){
					e.printStackTrace();
				}
			}
		});
	}

	private static void loadDemoData() {
		DemoData dd = new DemoData();
		dd.loadDemoData();
		System.out.println("\n");
	}
	
	private static void createTeachingBlock() {
		ClassCtr cCtr = new ClassCtr();
		
		Class cl1 = cCtr.findClass("1. Klasse");
		
		cCtr.createTeachingBlock(cl1, "Mathematics", 6, "Bio");
		cCtr.createTeachingBlock(cl1, "History", 4, "Gym");
		cCtr.createTeachingBlock(cl1, "English", 4, "L01");
		cCtr.createTeachingBlock(cl1, "Danish", 6, "L02");
		cCtr.createTeachingBlock(cl1, "Geography", 4, "L03");
		
		Class cl2 = cCtr.findClass("2. Klasse");
				
		cCtr.createTeachingBlock(cl2, "Mathematics", 6, "L01");
		cCtr.createTeachingBlock(cl2, "History", 6, "Bio");
		cCtr.createTeachingBlock(cl2, "English", 6, "Gym");
		cCtr.createTeachingBlock(cl2, "Danish", 6, "L02");
		cCtr.createTeachingBlock(cl2, "Geography", 6, "L03");
		
		for (TeachingBlock tb : cl1.getTbList()){
			System.out.println(tb);
		}
		
		for (TeachingBlock tb : cl2.getTbList()){
			System.out.println(tb);
		}
		System.out.println("\n");
	}

	private static void createSchedule() {
		ScheduleCtr schCtr = new ScheduleCtr();
		ClassCon clCon = ClassCon.getInstance();
		
		schCtr.createSchedule("1. Klasse", 0, 36);
		schCtr.createSchedule("2. Klasse", 0, 36);
		
		System.out.println("\n" + clCon.findClassByName("1. Klasse").getSchedule());
		System.out.println("--------------------------------1.Klasse--------------------------------");
		System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag");
		List<Block> list1 = clCon.findClassByName("1. Klasse").getSchedule().getBlocks();
		for (int i = 0; i < list1.size(); i = i+5 ){
			if (i == 0 || i == 5  || i == 10 || i == 15 || i == 20 || i == 25 || i == 30 ){
				System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", list1.get(i), list1.get(i+1), list1.get(i+2), list1.get(i+3), list1.get(i+4) + "\n");
			}
		}
		System.out.println();
		
		System.out.println("\n" + clCon.findClassByName("2. Klasse").getSchedule());
		System.out.println("--------------------------------2.Klasse--------------------------------");
		System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag");
		List<Block> list2 = clCon.findClassByName("2. Klasse").getSchedule().getBlocks();
		for (int i = 0; i < list2.size(); i = i+5 ){
			if (i == 0 || i == 5  || i == 10 || i == 15 || i == 20 || i == 25 || i == 30 ){
				System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", list2.get(i), list2.get(i+1), list2.get(i+2), list2.get(i+3), list2.get(i+4) + "\n");
			}
		}
		System.out.println();
	}
	
	private static void moveTeachingBlock(){
		ScheduleCtr schCtr = new ScheduleCtr();
		ClassCon clCon = ClassCon.getInstance();
		
		/////////////////////////////// 1. Klasse
		
		schCtr.moveTeachingBlock("1. Klasse", "1Mat1", 28);
		schCtr.moveTeachingBlock("1. Klasse", "1His1", 1);
		schCtr.moveTeachingBlock("1. Klasse", "1Dan1", 2);
		schCtr.moveTeachingBlock("1. Klasse", "1Mat2", 28);
		schCtr.moveTeachingBlock("1. Klasse", "1His2", 3);
		
		List<Block> list1 = clCon.findClassByName("1. Klasse").getSchedule().getBlocks();
		
		System.out.println("--------------------------------1.Klasse--------------------------------");
		System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag");
		for (int i = 0; i < list1.size(); i = i+5 ){
			if (i == 0 || i == 5  || i == 10 || i == 15 || i == 20 || i == 25 || i == 30 ){
				System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", list1.get(i), list1.get(i+1), list1.get(i+2), list1.get(i+3), list1.get(i+4) + "\n");
			}
		}
		System.out.println();
		
		////////////////////////// 2. Klasse
		
		schCtr.moveTeachingBlock("2. Klasse", "2Mat1", 1);
		schCtr.moveTeachingBlock("2. Klasse", "2Mat2", 28);
		
		List<Block> list2 = clCon.findClassByName("2. Klasse").getSchedule().getBlocks();
		
		System.out.println("--------------------------------2.Klasse--------------------------------");
		System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag");
		for (int i = 0; i < list2.size(); i = i+5 ){
			if (i == 0 || i == 5  || i == 10 || i == 15 || i == 20 || i == 25 || i == 30 ){
				System.out.printf("%-15s %-15s %-15s %-15s %-15s %n", list2.get(i), list2.get(i+1), list2.get(i+2), list2.get(i+3), list2.get(i+4) + "\n");
			}
		}
		System.out.println();		
	}

	private static void runApplication() {
		
		loadDemoData();
		createTeachingBlock();
		createSchedule();
		moveTeachingBlock();
		
	}
	
}
